package com.example.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.pojo.SysOffice;
import com.example.mapper.SysOfficeMapper;
import com.example.service.ISysOfficeService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.vo.SysOfficeVo;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

import java.util.Map;

/**
 * <p>
 * 机构表 服务实现类
 * </p>
 *
 * @author lyj
 * @since 2023-02-15
 */
@Service
public class SysOfficeServiceImpl extends ServiceImpl<SysOfficeMapper, SysOffice> implements ISysOfficeService {

    @Override
    public Page<SysOfficeVo> queryByCondition(Page<SysOfficeVo> page, Map<String, Object> map) {
        QueryWrapper<SysOfficeVo> wrapper = new QueryWrapper<>();
        wrapper.apply(" so.del_flag=0 ")
                .eq(!ObjectUtils.isEmpty(map.get("areaId")), "sa.id", map.get("areaId"))
                .and(!ObjectUtils.isEmpty(map.get("keyWord"))
                        , qw -> qw.like("so.name", map.get("keyWord")).or()
                                .like("so.address", map.get("keyWord")).or()
                                .like("so.master", map.get("keyWord")));
        return baseMapper.queryByCondition(page, wrapper);
    }

    @Override
    public SysOffice queryByUserId(Long createUserId) {

        return baseMapper.queryByUserId(createUserId);
    }
}
